#!/usr/bin/env python
import sys
import re

def main():

   arr = []
   i = 0
   length = 0
   maxlength = 0

   if len(sys.argv) == 2:

      f = open(sys.argv[1])
      for line in f:

         result = re.compile(r'\d+x\d+').search(line)
         if result:
            product = int(result.group().split('x')[0]) * int(result.group().split('x')[1])
            sys.stderr.write('%s,%d\n' %(line[:-1], product))
            arr[i - 1].append(product)
            length += 1;

         else:
            sys.stderr.write(line)
            arr.append([])
            i += 1;
            if length > maxlength:
               maxlength = length
            length = 0;

      columns = i - 1;

      f.close()

      for row in range(0, maxlength):
         for column in range(0, columns):
            if row < len(arr[column]):
               print str(arr[column][row]) + ',' ,
            else:
               print ',' ,
         print

   else:
      print("Usage: %s file" % sys.argv[0])

if __name__ == "__main__":
   main()
